<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>列表页</title>
    <meta name="description"
        content="京东JD.COM-专业的综合网上购物商城,销售家电、数码通讯、电脑、家居百货服装服饰、母婴、图书、食品等数万个品牌优质商品.便捷、诚信的服务，为您提供愉悦的网上购物体验!" />
    <meta name="Keywords" content="网上购物,网上商城,手机,笔记本,电脑,MP3,CD,VCD,DV,相机,数码,配件,手表,储卡,京东" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/normalize.css" />
    <link rel="stylesheet" href="css/base.css" />
    <link rel="stylesheet" href="css/list.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/base.js"></script>
    <script src="js/list.js"></script>
    <script src="js/axios.min.js"></script>
    <!-- import Vue before Element -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<style>
    .sk_goods_title {
        overflow: hidden;
        -webkit-line-clamp: 1;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
    }

    .coomdityName {
        overflow: hidden;
        -webkit-line-clamp: 1;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
    }

    .el-pagination.is-background .el-pager li:not(.disabled).active {
        background-color: #f10215;
        color: #FFF;
    }

    .el-pagination.is-background .el-pager li:not(.disabled):hover {
        color: #f10215;
    }
</style>

<body>
    <div id="app">
        <header>
            <a href="#">
                <img src="images/header.jpg" height="80" width="100%" alt="">
            </a>
        </header>
        <div>
            <iframe MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no src="heade.html"
                height="30px" width="100%"></iframe>
        </div>
        <div class="m">
            <div class="w middle">
                <div class="logo">
                    <h1 class="small">
                        <!-- 提高权重 便利于搜索引擎优化 -->
                        <a href="index.html" title="京东">京东</a>
                    </h1>
                </div>

                <div class="form">
                    <!-- <input  v-model="inputName" type="text" placeholder="扫描仪"> -->
                    <el-row class="demo-autocomplete" id="app">
                        <el-col>
                            <el-autocomplete style="width: 495px;
                        height: 33px;
                        border: 1px solid #f10215;
                        float: left;
                        font-size: 14px;" id="text" :span="12" v-model="inputName" :fetch-suggestions="querySearch"
                                placeholder="请输入内容" :trigger-on-focus="false" @select="handleSelect"></el-autocomplete>
                            <button v-if="inputName != null && inputName != ''"
                                @click="getCommodityByName"><i></i></button>
                            <button v-if="inputName == null || inputName == ''" @click="getList"><i></i></button>
                        </el-col>
                    </el-row>
                </div>
                <div class="shopCar">
                    <i></i><a href="cart.html" class="f10">我的购物车</a><span>8</span>
                </div>
                <div class="hotwords">
                    <a href="#" class="f10">199减100</a>
                    <a href="#">鼠标试用</a>
                    <a href="#">农资7折</a>
                    <a href="#">低至29元</a>
                    <a href="#">抽奖赢空调</a>
                    <a href="#">记忆棉</a>
                    <a href="#">坐垫</a>
                    <a href="#">1分钱买油</a>
                    <a href="#">智能手表</a>
                </div>

            </div>
        </div>

        <div class="w sk_container">
            <div class="sk_bd">
                <ul>
                    <li class="sk_goods" style="height:380px" v-for="commodity in commodityList" :key="commodity.id">
                        <a @click='gotoDetail(commodity.itemNumber)'><img :src="commodity.exhibition"></a>
                        <h5 class="sk_goods_title">{{commodity.exName}}</h5>
                        <p class="sk_goods_price"><em>¥{{commodity.price}}</em></p>
                        <div class="sk_goods_progress">
                            已售<i>{{commodity.salesVolume}}%</i>
                            <div class="bar" style="border: none;">
                                <!-- <div class="bar_in"></div> -->
                            </div>
                            剩余<em>{{commodity.stock}}</em>件
                        </div>
                    </li>
                </ul>
            </div>

            <div class="sk_page">
                <span class="page_skip">
                    <div class="page_num">
                        <el-pagination background @current-change="getPage" :current-page.sync="page" :page-size="limit"
                            layout="prev, pager, next, jumper" :total="total">
                        </el-pagination>
                    </div>
                </span>
            </div>
        </div>
        <footer>
            <div class="service">
                <!-- 服务模块 -->
                <div class="w">
                    <ul>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                    </ul>
                </div>
            </div>
            <!-- 帮助模块 -->
            <div class="w help">
                <div class="fl">
                    <dl>
                        <dt>购物指南</dt>
                        <dd><a href="#">购物流程</a></dd>
                        <dd><a href="#">会员介绍</a></dd>
                        <dd><a href="#">生活旅行</a></dd>
                        <dd><a href="#">常见问题</a></dd>
                        <dd><a href="#">大家电</a></dd>
                        <dd><a href="#">联系客服</a></dd>
                    </dl>
                    <dl>
                        <dt>配送方式</dt>
                        <dd><a href="#">上门自提</a></dd>
                        <dd><a href="#">211限时达</a></dd>
                        <dd><a href="#">配送服务查询</a></dd>
                        <dd><a href="#">配送费收取标准</a></dd>
                        <dd><a href="#">海外配送</a></dd>
                    </dl>
                    <dl>
                        <dt>支付方式</dt>
                        <dd><a href="#">货到付款</a></dd>
                        <dd><a href="#">在线支付</a></dd>
                        <dd><a href="#">分期付款</a></dd>
                        <dd><a href="#">邮局汇款</a></dd>
                        <dd><a href="#">公司转账</a></dd>
                    </dl>
                    <dl>
                        <dt>售后服务</dt>
                        <dd><a href="#">售后政策</a></dd>
                        <dd><a href="#">价格保护</a></dd>
                        <dd><a href="#">退款说明</a></dd>
                        <dd><a href="#">返修/退换货</a></dd>
                        <dd><a href="#">取消订单</a></dd>
                    </dl>
                    <dl>
                        <dt>特色服务</dt>
                        <dd><a href="#">夺宝岛</a></dd>
                        <dd><a href="#">DIY装机</a></dd>
                        <dd><a href="#">延保服务</a></dd>
                        <dd><a href="#">京东E卡</a></dd>
                        <dd><a href="#">京东通信</a></dd>
                        <dd><a href="#">京鱼座智能</a></dd>
                    </dl>
                </div>
                <div class="fr coverage">
                    <h5>京东自营覆盖区县</h5>
                    <p>京东已向全国2661个区县提供自营配送服务，支持货到付款、POS机刷卡和售后上门服务。</p>
                    <a href="#">查看详情 > </a>
                </div>
            </div>
            <div class="w copyright">
                <p>
                    <a href="#">关于我们</a>
                    <span> | </span>
                    <a href="#">联系我们</a>
                    <span> | </span>
                    <a href="#">联系客服</a>
                    <span> | </span>
                    <a href="#">合作招商</a>
                    <span> | </span>
                    <a href="#">商家帮助</a>
                    <span> | </span>
                    <a href="#">营销中心</a>
                    <span> | </span>
                    <a href="#">手机京东</a>
                    <span> | </span>
                    <a href="#">友情链接</a>
                    <span> | </span>
                    <a href="#">销售联盟</a>
                    <span> | </span>
                    <a href="#">京东社区</a>
                    <span> | </span>
                    <a href="#">风险监测</a>
                    <span> | </span>
                    <a href="#">隐私政策</a>
                    <span> | </span>
                    <a href="#">京东公益</a>
                    <span> | </span>
                    <a href="#">English Site</a>
                    <span> | </span>
                    <a href="#">Media & IR</a>
                </p>
                <div>
                    <p>京公网安备
                        11000002000088号<span>|</span>京ICP证070359号<span>|</span>互联网药品信息服务资格证编号(京)-经营性-2014-0008<span>|</span>新出发京零
                        字第大120007号</p>
                    <p>互联网出版许可证编号新出网证(京)字150号<span>|</span>出版物经营许可证<span>|</span>网络文化经营许可证京网文[2014]2148-348号<span>|</span>违法和不良信息举报电话：4006561155
                    </p>
                    <p>Copyright © 2004 - 2019 京东JD.com
                        版权所有<span>|</span>消费者维权热线：4006067733经营证照|(京)网械平台备字(2018)第00003号<span>|</span>营业执照</p>
                    <p>Global Site<span>|</span>Сайт России<span>|</span>Situs Indonesia<span>|</span>Sitio de
                        España<span>|</span>เว็บไซต์ประเทศไทย</p>
                    <p>京东旗下网站：京东钱包<span>|</span>京东云</p>
                </div>
                <p class="foot-icon">
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                </p>
            </div>
        </footer>
    </div>
</body>

<script>
    new Vue({
        el: '#app',
        data: {
            commodityList: [],//存放所有商品对象
            inputName: '',//输入的商品名称
            searchObj: [],//搜索框回显数据
            page: 1, // 当前页
            limit: 10, // 每页个数
            total: 1, // 总页码

            name: "", // 用户登录显示的名称
        },
        created() {
            this.showInfo();
            this.getList();
        },
        methods: {
            showInfo() {
                let token = this.getCookie("token");
                if (token) {
                    this.name = this.getCookie("name");
                }
            },
            //获取所有商品
            getList() {
                axios.get(`http://localhost/admin/commodity/findAll/1/${this.limit}`)
                    .then(response => {
                        let resData = response.data.data;
                        this.commodityList = resData.data;
                        this.page = 1;
                        this.total = resData.total;
                    })
            },
            //根据名称进行模糊查询商品名字
            querySearch(queryString, cb) {
                this.searchObj = [];
                if (queryString == "") return;
                axios.post(`http://localhost/admin/commodity/list/1/10`, {
                    name: queryString
                }).then(response => {
                    let resData = response.data.data.data;
                    for (let i = 0; i < resData.length; i++) {
                        this.searchObj[i] = { 'value': resData[i].name, "id": resData[i].id };
                    }
                    // 调用 callback 返回建议列表的数据 
                    cb(this.searchObj, cb);
                })

            },
            //搜索框回显
            handleSelect(item) {
                axios.post(`http://localhost/admin/commodity/list/${this.page}/${this.limit}`, {
                    name: item.value
                }).then(response => {
                    let resData = response.data.data;
                    this.commodityList = resData.data;
                })
            },
            //根据名称进行模糊查询并更新商品列表
            getCommodityByName() {
                axios.post(`http://localhost/admin/commodity/list/${this.page}/${this.limit}`, {
                    name: this.inputName
                }).then(response => {
                    let resData = response.data.data;
                    this.commodityList = resData.data;
                    this.total = resData.total;
                })
            },
            getPage(page = 1) {
                this.page = page
                this.commodityList = null
                this.activeIndex = 0
                this.getCommodityPage();
            },
            //分页方法    
            getCommodityPage() {
                axios.get(`http://localhost/admin/commodity/findAll/${this.page}/${this.limit}`)
                    .then(response => {
                        let resData = response.data.data;
                        this.commodityList = resData.data;
                        this.total = resData.total;
                    })
            },
            gotoDetail(itemNumber) {
                window.open('detail.html?itemNumber=' + itemNumber);
            },
            getCookie(name) {
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg)) {
                    return unescape(arr[2]);

                } else {
                    return null;
                }
            }


        }
    })

</script>

</html>